/*
//
//              INTEL CORPORATION PROPRIETARY INFORMATION
//  This software is supplied under the terms of a license  agreement or
//  nondisclosure agreement with Intel Corporation and may not be copied
//  or disclosed except in  accordance  with the terms of that agreement.
//    Copyright (c) 2007 Intel Corporation. All Rights Reserved.
//
//
*/

#include "umc_defs.h"
#if defined(UMC_ENABLE_AVS_SPLITTER)

#include "umc_start_code_array.h"

namespace UMC
{

enum
{
    DEFAULT_NUMBER_OF_ITEMS     = 16
};

StartCodeArray::StartCodeArray(void)
{
    m_pStartCodes = NULL;
    m_iAllocated = 0;

} // StartCodeArray::StartCodeArray(void)

StartCodeArray::~StartCodeArray(void)
{
    Close();

} // StartCodeArray::~StartCodeArray(void)

Status StartCodeArray::Close(void)
{
    if (m_pStartCodes)
        delete [] m_pStartCodes;

    // reset variables
    m_pStartCodes = NULL;
    m_iAllocated = 0;

    return UMC_OK;

} // Status StartCodeArray::Close(void)

Status StartCodeArray::Init(void)
{
    // close before initialization
    Close();

    // allocated default array
    m_pStartCodes = new StartCodeDesc[DEFAULT_NUMBER_OF_ITEMS];
    if (NULL == m_pStartCodes)
        return UMC_ERR_ALLOC;
    m_iAllocated = DEFAULT_NUMBER_OF_ITEMS;

    return UMC_OK;

} // Status StartCodeArray::Init(void)

Status StartCodeArray::Reallocate(Ipp32s iNum)
{
    StartCodeDesc *pTemp;

    // check error(s)
    if (iNum < m_iAllocated)
        return UMC_OK;

    // allocate a new array
    pTemp = new StartCodeDesc[iNum];
    if (NULL == pTemp)
        return UMC_ERR_ALLOC;

    // exchange the arrays
    memcpy(pTemp, m_pStartCodes, sizeof(StartCodeDesc) * m_iAllocated);
    delete [] m_pStartCodes;
    m_pStartCodes = pTemp;
    m_iAllocated = iNum;

    return UMC_OK;

} // Status StartCodeArray::Reallocate(Ipp32s iNum)

} // namespace UMC

#endif // #if defined(UMC_ENABLE_AVS_SPLITTER)
